import { IFeidaoAiMobile } from '@dfeidao/atom-mobile/interfaces';
import get from '@dfeidao/atom-mobile/local/get';
import post from '@dfeidao/atom-mobile/msg/post';
import replace from '@dfeidao/atom-mobile/nav/replace';
import set from '@dfeidao/atom-mobile/storage/set';
import { Alert } from 'react-native';
import { login } from '../atom/config';



export default async function a004(fd: IFeidaoAiMobile) {
	// 登录
	const user = get(fd, 'user') as { usercode: string, userpw: string };
	if (user.usercode === '') {
		Alert.alert('帐号不能为空');
		return;
	}
	if (user.userpw === '') {
		Alert.alert('密码不能为空');
		return;
	}

	try {
		const body = JSON.stringify(user);
		const res = await post(login, body) as { usercode: string, user_name: string, productid: string, sessionID: string };
		await set('user', JSON.stringify(res));
		// fd.page.props.navigation.navigate('app_home');
		replace(fd, 'app_home', {});
	} catch (err) {
		Alert.alert(err.message);
	}

}
